package com.czxy.demo01;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class  Test07 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        show(list);
    }

    public static void show(List<Integer> list){
        Scanner sc = new Scanner(System.in);

        while (true){
            System.out.println("1.发牌");
            System.out.println("2.结束发牌");
            System.out.println("请输入程序序号");
            int i = sc.nextInt();
            switch (i){
                case 1:
                    fapai(list);
                    break;
                case 2:
                    System.out.println("您现在手上的牌有：");
                    for (int j = 0; j <list.size() ; j++) {
                        System.out.print(list.get(i));
                    }
                    list.clear();
                    break;
            }
        }
    }

    public static void fapai(List<Integer> list){
       int num = new Random().nextInt(13 - 1)+1;
       list.add(num);

        int sum = 0;
        for (int i = 0; i <list.size(); i++) {
            sum+=list.get(i);
        }

        if(sum<=21){
            System.out.print("手上牌有:");
            for (int i = 0; i <list.size() ; i++) {
                System.out.print(list.get(i)+"  ");
            }
            System.out.println();
            System.out.println("点数为"+sum);
        }else {
            System.out.println("点数为"+sum+"大于21 结束游戏");
            System.exit(0);
        }
    }
}
